#include <stdio.h>
#include <unistd.h>
#include <stdbool.h>

#include "tlinklist.h"
#include "slinklist.h"
#include "filedata.h"
#include "function.h"
#include "screen.h"

int main()
{
	//创建链表
	pLink PL = (pLink)malloc(sizeof(pLink));
	tLink TL = Create_tLink();
	sLink SL = Create_sLink();
	
	//数据加载
	Read_Data_P(PL);
	Read_Data_T(TL);
	Read_Data_S(SL);

	//分数排名
	Sort_sLink(SL,SL->head,SL->tail,1);
	
	//数据处理
	bool out_1 = false;
	int cur_id = -1;
	while(1)
	{
		switch(Login_Screen())
		{
			case 0 : //学生登录
			{
				bool out_2 = false;
				cur_id = Login_S(SL);
				if(cur_id == -1) break;
				while(1)
				{
					switch(Student_Screen(SL,cur_id))
					{
						case 0 : Check_Score_SP(SL,cur_id);break;
						case 1 : Reset_Password_S(SL,cur_id);break;
						case 9 : out_2 = true;break;
						default : continue;
					}
					if(out_2 == true) break;
				}
				break;
			}
			case 1 : //教师登录
			{
				bool out_2 = false;
				cur_id = Login_T(TL);
				if(cur_id == -1) break;
				while(1)
				{
					switch(Teacher_Screen(TL,cur_id))
					{
						case 0 : Batch_Input_SD(SL);break;
						case 1 : Batch_Input_SS(SL);break;
						case 2 : Check_Modify_SD(SL);break;
						case 3 : Check_Quit_SD(SL);break;
						case 4 : Check_SSC(SL);break;
						case 5 : Reset_Password_T(TL,cur_id);break;
						case 9 : out_2 = true;break;
						default : continue;
					}
					if(out_2 == true) break;
				}
				break;
			}
			case 2 : //校长登录
			{
				bool out_2 = false;
				if(Login_P(PL) == false) break;
				while(1)
				{
					switch(Principal_Screen(PL))
					{
						case 0 : Simple_Input_TD(TL);break;
						case 1 : Check_Modify_TD(TL);break;
						case 2 : Check_Quit_TD(TL);break;
						case 3 : Reset_Password_P(PL);break;
						case 9 : out_2 = true;break;
						default : continue;
					}
					if(out_2 == true) break;
				}
				break;
			}
			case 3 : //开发人员登录
			{
				bool out_2 = false;
				if(Login_D() == false) break;
				while(1)
				{
					switch(Developer_Screen())
					{
						case 0 : Modify_Password_P(PL);break;
						case 1 : Init_System(PL,TL,SL);break;
						case 9 : out_2 = true;break;
						default : continue;
					}
					if(out_2 == true) break;
				}
				break;
			}
			case 9 : //退出系统
			{
				out_1 = true;
				break;
			}
			default : continue;
		}
		if(out_1 == true) break;
	}

	//保存数据
	//Write_Data_P(PL);
	//Write_Data_T(TL);
	//Write_Data_S(SL);
}
